package com.project.easy.common.framework.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.easy.common.db.mybatisplus.core.util.PageConvertTool;
import  com.project.easy.common.util.dto.PageResDto;
import  com.project.easy.common.util.string.StringUtil;
import com.project.easy.common.framework.web.entity.FrameworkOperationLog;
import com.project.easy.common.framework.web.entity.dto.OperationLogPageReq;
import com.project.easy.common.framework.web.mapper.FrameworkOperationLogMapper;
import com.project.easy.common.framework.web.service.IFrameworkOperationLogService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author GreatorMan.cool
 * @copyright: Copyright (c) 2020
 * @company: 扬起科技有限公司
 * @date 2021/10/26 22:43
 * @description: 日志服务
 */
@Service
public class FrameworkOperationLogServiceImpl extends ServiceImpl<FrameworkOperationLogMapper, FrameworkOperationLog> implements IFrameworkOperationLogService {
    /**
     * 列表查询
     *
     * @param operationLogPageReq 请求参数
     * @return 返回分页列表查询
     */
    @Override
    public PageResDto<FrameworkOperationLog> queryList(OperationLogPageReq operationLogPageReq) {
        Page<FrameworkOperationLog> page = new Page<>(operationLogPageReq.getPageNum(), operationLogPageReq.getPageSize());
        QueryWrapper<FrameworkOperationLog> queryWrapper = new QueryWrapper<>();
        if (StringUtil.isNotBlank(operationLogPageReq.getIp())) {
            queryWrapper.like("ip", operationLogPageReq.getIp());
        }
        if (StringUtil.isNotBlank(operationLogPageReq.getLogStatus())) {
            queryWrapper.eq("log_status", operationLogPageReq.getLogStatus());
        }
        if (Objects.nonNull(operationLogPageReq.getStart())) {
            queryWrapper.gt("create_time", operationLogPageReq.getStart());
        }
        if (Objects.nonNull(operationLogPageReq.getEnd())) {
            queryWrapper.gt("create_time", operationLogPageReq.getEnd());
        }
        Page<FrameworkOperationLog> result  = this.baseMapper.selectPage(page, queryWrapper);
        return PageConvertTool.convert(result);
    }
}
